package _1436_Destination_City;

import _0000_study._common.Build;

import java.util.HashMap;
import java.util.List;

/**
 * Date: 2021/10/1 9:58
 * Content:
 * 执行用时：3 ms, 在所有 Java 提交中击败了30.79%的用户
 * 内存消耗：38.1 MB, 在所有 Java 提交中击败了44.21%的用户
 */
public class Solution {

    public String destCity(List<List<String>> paths) {
        HashMap<String, Integer> hash = new HashMap<>();
        for (List<String> path : paths) {
            String a = path.get(0), b = path.get(1);
            hash.put(a, hash.getOrDefault(a, 0) + 1);
            if (!hash.containsKey(b)) hash.put(b, 0);
        }
        for (String k : hash.keySet()) {
            int v = hash.get(k);
            if (v == 0) return k;
        }
        return "";
    }

    public static void main(String[] args) {

        List<List<String>> paths = Build.build(new String[][]{
                {"London",   "New York"},
                {"New York", "Lima"},
                {"Lima",     "Sao Paulo"}
        });
        System.out.println((new Solution()).destCity(paths));
    }
}
